package com.kt.common.clazz.interface1.extensionfun

fun main() {

    /*val list = mutableListOf(1, 2, 3, 4, 54, 8, 9)

    list.swap(1, 9)
    list.println()*/
    Example().printFunctionType()
    Example().printFunctionType(223)
}

class Example {
    fun printFunctionType() { println("Class method") }
}

fun Example.printFunctionType() { println("Extension function") }

fun Example.printFunctionType(i: Int) { println("Extension function") }

//主要用来给对象的扩展

fun <T>MutableList<T>.swap(index1: Int, index2: Int) {
    if (this.size <= index1 || this.size <= index2) return
    val temp = this[index1]
    this[index1] = this[index2]
    this[index2] = temp
}

fun <T> MutableList<T>.println() {
    if (this.isNullOrEmpty()) {
        println("list is null")
        return
    }
    this.forEach {
        println(it)
    }
}